package com.example.shop.activity;

import android.os.Bundle;
import android.view.View;
import android.widget.ListView;
import android.widget.Toast;

import com.example.shop.Constant;
import com.example.shop.R;
import com.example.shop.adapter.ItemLvActivityTopicAdapter;
import com.example.shop.base.SCBaseActivity;
import com.example.shop.entity.TopicActivityEntity;
import com.example.shop.util.HttpNetUtil;
import com.example.sjlibrary.net.BaseJSONOverListener;
import com.example.sjlibrary.net.BaseNetForJSON;
import com.example.sjlibrary.net.BaseParams;

import butterknife.Bind;
import butterknife.ButterKnife;

public class TopicActivity extends SCBaseActivity implements View.OnClickListener {

    @Bind(R.id.lv_activity_topic)
    ListView mLvActivityTopic;
    private ItemLvActivityTopicAdapter mItemLvActivityTopicAdapter;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_topic);
        ButterKnife.bind(this);
        this.setTitleCenter("促销快报");
        this.setTvTitleBarLeft("返回", this);

        //联网操作
        BaseParams baseParams = new BaseParams();
        baseParams.addParam("page", "1");
        baseParams.addParam("pageNum", "5");
        BaseNetForJSON baseNetForJSON = HttpNetUtil.getNetRequest(Constant.TOPIC_URL, baseParams, TopicActivityEntity.class, new TopicNetOver());
        baseNetForJSON.netForJSON();
    }

    @Override
    public void onClick(View v) {
        killSelf();
    }

    private class TopicNetOver implements BaseJSONOverListener<TopicActivityEntity> {

        @Override
        public void onError() {
            Toast.makeText(mActivitySelf, "联网失败", Toast.LENGTH_SHORT).show();

        }

        @Override
        public void onSuccess(TopicActivityEntity entity) {
            if (mItemLvActivityTopicAdapter==null){
                mItemLvActivityTopicAdapter=new ItemLvActivityTopicAdapter(mActivitySelf,entity.getTopic());
                mLvActivityTopic.setAdapter(mItemLvActivityTopicAdapter);
            }

        }
    }
}
